const util = require('../../utils/util.js')
Page({
    data: {
        username: '',
        password: '',
        role: 'STAFF',
        // name: '',
        // sex: '',
        // phone: '',
        // hidden: true,
    },
    onInput(e) {
        this.data[e.currentTarget.dataset.name] = e.detail.value
        this.setData(this.data)
    },
    login() {
        console.log(this.data.username + ' ' + this.data.password+' '+this.data.role)
        util.http('/wx/login', this.data, resp => {
          console.log(resp.data)
          console.log(resp.data.id)
          console.log(resp.data.name)
          if (resp.code == 200) {
                wx.setStorageSync('id', resp.data.id)
                wx.setStorageSync('name', resp.data.name)
                wx.switchTab({
                    url: '../index/index',
                })
            } else {
                util.alert(resp.msg)
                this.setData(this.data)
                if (resp.msg == '没有此账号，请注册') {
                    this.setData(this.data)
                }
            }
            // if (resp.code == 1) {
            //     wx.setStorageSync('id', resp.uid)
            //     wx.setStorageSync('name', resp.name)
            //     wx.switchTab({
            //         url: '../index/index',
            //     })
            // } else {
            //     util.alert(resp.msg)
            //     this.setData(this.data)
            //     if (resp.msg == '没有此账号，请注册') {
            //         this.data.hidden = false
            //         this.setData(this.data)
            //     }
            // }
        })
    },
    onLoad(options) {//页面主函数
        if (wx.getStorageSync('id')) {
            wx.switchTab({
                url: '../index/index',
            })
        }
    }
})